home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / database / tbl.c < prev    next >
Text File  |  1984-05-21  |  3KB  |  116 lines

  1. /* SDB - table output routines */
  2.  
  3. #include "stdio.h"
  4. #include "sdbio.h"
  5.  
  6. static char buffer[TABLEMAX+1];
  7. int bndx;
  8.  
  9. /* db_thead - print a table header */
  10. db_thead(fp,slptr)
  11.   FILE *fp; struct sel *slptr;
  12. {
  13.     struct sattr *saptr;
  14.     int twidth,fwidth,i;
  15.     char *aname;
  16.  
  17.     /* compute the table width */
  18.     twidth = 1;
  19.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next)
  20.         twidth += saptr->sa_attr->at_size + 3;
  21.  
  22.     /* print the top line of the table */
  23.     bstart();
  24.     for (i = 0; i < twidth; i++)
  25.         binsert('-');
  26.     bprint(fp);
  27.  
  28.     /* print the label line of the table */
  29.     bstart();
  30.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next) {
  31.         fwidth = saptr->sa_attr->at_size;
  32.         binsert('|'); binsert(' ');
  33.         if ((aname = saptr->sa_name) == NULL)
  34.             aname = saptr->sa_aname;
  35.         for (i = 0; i < fwidth; i++)
  36.             if (*aname != 0)
  37.                 binsert(*aname++);
  38.             else
  39.                 binsert(' ');
  40.         binsert(' ');
  41.     }
  42.     binsert('|');
  43.     bprint(fp);
  44.  
  45.     /* print the line under the labels */
  46.     bstart();
  47.     for (i = 0; i < twidth; i++)
  48.         binsert('-');
  49.     bprint(fp);
  50. }
  51.  
  52. /* db_tfoot - print a table foot */
  53. db_tfoot(fp,slptr)
  54.   FILE *fp; struct sel *slptr;
  55. {
  56.     struct sattr *saptr;
  57.     int twidth,i;
  58.  
  59.     /* compute the table width */
  60.     twidth = 1;
  61.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next)
  62.         twidth += saptr->sa_attr->at_size + 3;
  63.  
  64.     /* print the line at the foot of the table */
  65.     bstart();
  66.     for (i = 0; i < twidth; i++)
  67.         binsert('-');
  68.     bprint(fp);
  69. }
  70.  
  71. /* db_tentry - print a table entry */
  72. db_tentry(fp,slptr)
  73.   FILE *fp; struct sel *slptr;
  74. {
  75.     struct sattr *saptr;
  76.     int fwidth,i;
  77.  
  78.     /* print a table entry */
  79.     bstart();
  80.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next) {
  81.         fwidth = saptr->sa_attr->at_size;
  82.         binsert('|'); binsert(' ');
  83.         for (i = 0; i < fwidth; i++)
  84.             if (saptr->sa_aptr[i] != 0)
  85.                 binsert(saptr->sa_aptr[i]);
  86.             else
  87.                 binsert(' ');
  88.         binsert(' ');
  89.     }
  90.     binsert('|');
  91.     bprint(fp);
  92. }
  93.  
  94. /* bstart - start building a line */
  95. static bstart()
  96. {
  97.     bndx = 0;
  98. }
  99.  
  100. /* binsert - insert a character into the buffer */
  101. static binsert(ch)
  102.   int ch;
  103. {
  104.     if (bndx < TABLEMAX)
  105.         buffer[bndx++] = ch;
  106. }
  107.  
  108. /* bprint - print the current line */
  109. static bprint(fp)
  110.   FILE *fp;
  111. {
  112.     buffer[bndx] = EOS;
  113.     fprintf(fp,"%s\n",buffer);
  114. }
  115.  
  116.